package com.group.controller;


import com.group.pojo.Job;
import com.group.service.JobService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author group
 * @since 2021-09-06
 */
@RestController
public class JobController {

    @Autowired
    private JobService jobService;

    //测试成功，查询全部
    @GetMapping("findAll")
    @ResponseBody  //视图显示
    public List<Job> findAll(Job job){
        List<Job> list =jobService.findAll();
        return list;
    }

    //测试成功，模糊查询
    @RequestMapping("findJobVague")
    @ResponseBody
    public List<Job> findJobVague(Job job){



        List<Job> jobList = jobService.findJobVague(job);

        return jobList;

    }


//    测试成功，单条删除(根据id)
    @RequestMapping("delJobById")
    @ResponseBody
    public Integer delJobById(){
        boolean flag =jobService.delJobById(2); //获取id
        if(flag) {
            System.out.println("成功！");
            return 1;
        }else{
            System.out.println("gg");
            return 0;
        }
    }

//    测试成功，手动添加
    @RequestMapping("addJob")
    @ResponseBody
    public String addJob(Job job){




        boolean flag = jobService.addJob(job);
        if(flag){
            return "success";
        }else{
            return "false";
        }
    }

//    测试成功，修改
    @RequestMapping("updateJob")
    @ResponseBody
    public String updataJob(Job job){



        boolean flag = jobService.updateJob(job);
        if(flag){
            return "success";
        }else{
            return "false";
        }
    }

    @RequestMapping("findJobById")
    @ResponseBody
    public List<Job> findJobById(int id){
        List<Job> list =jobService.findJobById(id);
        return list;
    }
}

